package cn.zeal4j.servlet.freemarker;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Administrator
 * @file IntelliJ IDEA FreeMarker
 * @create 2020 09 21 10:45
 */
@WebServlet("/fm-01")
public class FtlServlet extends HttpServlet {

    // 设置默认的转发路径，就和web.xml的默认模板引擎寻找路径一致
    // private final String TEMPLATE_ROOT_PATH = "freemarker-templates/";

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("message", "Hello FreeMarker TemplateEngine !!!");
        // req.getRequestDispatcher(TEMPLATE_ROOT_PATH + "fmt-01.ftl").forward(req, resp);
        req.getRequestDispatcher("freemarker-templates/fmt-01.ftl").forward(req, resp);
    }
}
